<?php

session_start();

require_once($_SERVER['DOCUMENT_ROOT'].'/incofarming/Functions/config.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/incofarming/Functions/class/koperasi_model.php');

$koperasi_model = new Koperasi_model();

$id_user = $_SESSION['id_user'];
$res = $koperasi_model->get_koperasi_data_from_iduser($id_user);

while($row = mysql_fetch_array($res)){
	$kode_telp = $koperasi_model->get_kota($row['IDKOTA']);
	$kode_telp = mysql_fetch_array($kode_telp);
	$prov =  $koperasi_model->get_prov($kode_telp['IDPROPINSI']);
	$prov = mysql_fetch_array($prov);
	$kop_data = array(
		'id_kop' => $row['IDKOPERASI'],
		'nama_kop' => $row['NAMAKOPERASI'],
		'alamat_kop' => $row['ALAMAT'],
		'no_telp' => $row['NOTELP'],
		'no_fax' => $row['NOFAX'],
		'tgl_berdiri' => $row['TGLBERDIRI'],
		'email' => $row['EMAIL'],
		'info_kop' => $row['INFORMASI'],
		'foto' => $row['IDFOTO'],
		'kode_telp' => $kode_telp['KODETELP'],
		'kota' => $kode_telp['NAMAKOTA'],
		'provinsi' => $prov['NAMAPROPINSI']
	);
}//var_dump($kop_data);

$_SESSION['id_kop'] = $kop_data['id_kop'];
$prod_res = $koperasi_model->get_koperasi_produk($kop_data['id_kop']);
if(mysql_num_rows($prod_res) > 0){
	$prod_arr = array();
	while($row = mysql_fetch_array($prod_res)){
		
		$besaran = mysql_fetch_array($koperasi_model->get_besaran($row['IDBESARAN']));
		
		if($row['KETERSEDIAAN'] == 1) $ava = "Tersedia";
		else $ava = "Tidak tersedia";
		
		$foto_res = $koperasi_model->get_foto($row['IDFOTO']);
		$foto = mysql_fetch_array($foto_res);
		
		$temp = array(
			'id_produk' => $row['IDPRODUK'],
			'nama_prod' => $row['NAMAPRODUK'],
			'harga_sat' => $row['HARGASAT'],
			'ava' => $ava,
			'besaran' => $besaran['BESARAN'],
			'foto' => $foto['IDFOTO']
		);
		
		$prod_arr[] = $temp;
	}
}


include($_SERVER['DOCUMENT_ROOT'].'/incofarming/Views/koperasi/dashkop_view.php');

?>